package com.simpe.boot.demo.common.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import java.io.Serializable;

@Configuration
public class RedisConfig
{
//    @Bean
//    JedisConnectionFactory jedisConnectionFactory()
//    {
//        JedisConnectionFactory connectionFactory = new JedisConnectionFactory();
//        connectionFactory.setHostName("192.168.0.112");
//        connectionFactory.setPort(6379);
//        connectionFactory.setDatabase(3);
//        JedisPoolConfig pool = new JedisPoolConfig();
//        connectionFactory.setPoolConfig(pool);
//        connectionFactory.afterPropertiesSet();
//        return connectionFactory;
//    }

    @Bean
    public RedisTemplate<Serializable, Object> redisTemplate(RedisConnectionFactory factory)
    {
        RedisTemplate<Serializable, Object> template = new RedisTemplate<Serializable, Object>();
        template.setConnectionFactory(factory);
        template.setKeySerializer(new StringRedisSerializer());
        template.afterPropertiesSet();
        return template;
    }
        
}